import { defineStore } from 'pinia';
import api from '@/api';

export const useSearchStore = defineStore('search', {
  actions: {
    async getSearchResponse(query: string, onData: (data: string) => void) {
      try {
        const cleanup = api.searchPopup.getSearchResponse(query, onData);
        return cleanup; // 返回清理函数，让组件可以手动关闭
      } catch (error) {
        console.error("搜索失败:", error);
        throw error;
      }
    },
  },
});